package com.erp.util
{
	import mx.validators.NumberValidator;
	import mx.validators.StringValidator;
	import mx.validators.Validator;
	import mx.events.ValidationResultEvent;
	import mx.core.UIComponent;


	public class ValidatorUtil
	{
		public function ValidatorUtil()
		{
		}

		private static var localManger:LocalResourceManager=LocalResourceManager.getInstance();

		private static var property:String="text";

		public static function stringValidator(source:Object):StringValidator
		{
			var sv:StringValidator=new StringValidator();
			sv.source=source;
			sv.property=property;
			sv.required=true;
			//sv.requiredFieldError=localManger.getString("err_user_required");
			
			
			
			return sv;
		}

		public static function numberValidator(source:Object):NumberValidator
		{
			var nv:NumberValidator=new NumberValidator();
			nv.source=source;
			nv.property=property;
			nv.required=false;
			nv.domain="int";
			nv.minValue=10;
			//nv.lowerThanMinError="太小了";
			return nv;
		}

		public static function validatorAll(validators:Array):Boolean
		{
			var validatorResults:Array=Validator.validateAll(validators);

			if (validatorResults.length > 0)
			{
				var vEvent:ValidationResultEvent=validatorResults[0] as ValidationResultEvent;
				(vEvent.target.source as UIComponent).setFocus();
				return false;
			}
			return true;
		}


	}
}